﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Configuration;
using System.Data.SqlServerCe;

namespace Randomizer
{
    /// <summary>
    /// Interaction logic for EditForm.xaml
    /// </summary>
    public partial class EditForm : Window
    {
        String _ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
        MainWindow mainwin;
        String itemName;

        public EditForm(MainWindow MainWin, string ItemName)
        {
            InitializeComponent();
            mainwin = MainWin;
            itemName = ItemName;
        }

        private void cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            string editQuery = "UPDATE Core_Table SET Name = '" + name.Text + "', Weight = '" + weight.Text + "', Cost = '" + cost.Text + "' WHERE Name = '" + itemName +"'";
            SqlCeConnection _Conn = new SqlCeConnection(_ConnectionString);
            SqlCeCommand comm = new SqlCeCommand(editQuery, _Conn);

            //Open DB and submit query
            _Conn.Open();
            comm.ExecuteNonQuery();
            _Conn.Close();

            //Refresh CustomGrid
            mainwin.BindCustomGrid();
            this.Close();
        
        }
    }
}
